<%@page import="com.zhuoshi.utils.DateHelper"%>
<%@page import="com.zhuoshi.bean.PaymentBean"%>
<%@page import="com.zhuoshi.dao.PaymentDao"%>
<%@page import="com.zhuoshi.bean.ContractMasterBean"%>
<%@page import="com.zhuoshi.dao.ContractMasterDao"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
request.setCharacterEncoding("UTF-8");
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

//合同数字编号
ContractMasterDao dao = new ContractMasterDao();
List<ContractMasterBean> list = dao.getAllList();
pageContext.setAttribute("list", list);

String id = request.getParameter("id");
PaymentDao paymentDao = new PaymentDao();
PaymentBean bean = paymentDao.getModel(Integer.parseInt(id));
pageContext.setAttribute("bean", bean);


String action = request.getParameter("action");
if("edit".equals(action)){
	
	String numerical = request.getParameter("numerical");
	String paydate = request.getParameter("returntime");
	String paymoney = request.getParameter("returnmoney");
	PaymentDao payDao = new PaymentDao();
	PaymentBean payBean = new PaymentBean();
	payBean.setNumerical(Integer.parseInt(numerical));
	payBean.setPaydate(DateHelper.strToDate(paydate));
	payBean.setPaymoney(Double.parseDouble(paymoney));
	payBean.setId(Integer.parseInt(id));
	int rows = payDao.update(payBean);
	if(rows>0){
		out.print("<script language='javascript'>alert('保存成功');location.href='payment_update.jsp?id="+bean.getId()+"';</script>");
	}else{
		out.print("<script language='javascript'>alert('保存成功');</script>");
	}
}

%>

<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
<meta http-equiv="Cache-Control" content="no-siteapp">
<link rel="Bookmark" href="http://localhost:8080/favicon.ico">
<link rel="Shortcut Icon" href="http://localhost:8080/favicon.ico">
<!--[if lt IE 9]>
<script type="text/javascript" src="lib/html5.js"></script>
<script type="text/javascript" src="lib/respond.min.js"></script>
<script type="text/javascript" src="lib/PIE_IE678.js"></script>
<![endif]-->
<link rel="stylesheet" type="text/css" href="template/H-ui.min.css">
<link rel="stylesheet" type="text/css" href="template/H-ui.admin.css">
<link rel="stylesheet" type="text/css" href="template/iconfont.css">
<link rel="stylesheet" type="text/css" href="template/icheck.css">
<link rel="stylesheet" type="text/css" href="template/skin.css" id="skin">
<link rel="stylesheet" type="text/css" href="template/style.css">


<title>添加回款信息 </title>


<script type="text/javascript">
function test(){
    var numerical = document.getElementById('numerical').value;
	  if(contractnum ==""){
		 document.form.numerical.focus();
     return false; 
	  }
	  var returntime = document.getElementById('returntime').value;
	  if(returntime ==""){
			 document.form.returntime.focus();
	     return false; 
		  }
	  var returnmoney = document.getElementById('returnmoney').value;
	  if(returnmoney ==""){
			 document.form.returnmoney.focus();
	     return false; 
		  }
	  return true;
	}
	</script><link rel="stylesheet" href="template/layer.css" id="layui_layer_skinlayercss">
	<link href="template/WdatePicker.css" rel="stylesheet" type="text/css"></head>

<body>
<article class="page-container">
	<form action="?action=edit" name="form" method="post" class="form form-horizontal" id="form-member-add" onSubmit="return test()">		
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>合同编号：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<!-- <input type="text" class="input-text" style="width:350px;" value="" placeholder="" id="contractnum" name="contractnum"> -->
				<select name="numerical" id="numerical" class="input-text" placeholder="" style="width:350px">
				<option value="">---请选择合同数字编号---</option>
				<c:forEach items="${list }" var="cmBean">
				<option value="${cmBean.numerical }" ${bean.numerical==cmBean.numerical? "selected" : "" }>${cmBean.numerical }</option>
				</c:forEach>
				</select>
			</div>
		</div>
		
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>回款日期：</label>
			<div class="formControls col-xs-8 col-sm-9">
					<input type="text" name="returntime" value="${bean.paydate }" onFocus="WdatePicker({maxDate:&#39;%y-%M-%d&#39;})" id="returntime" class="input-text Wdate" style="width:120px;">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>回款金额：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="${bean.paymoney }" style="width:350px;" placeholder="" id="returnmoney" name="returnmoney">
			</div>
		</div>
		
		<div class="row cl">
			<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
			<input type="hidden" value="${bean.id }" name="id" />
				<input class="btn btn-primary radius" id="send" type="submit" value="  提交  ">
				<input type="button" class="btn btn-danger radius" id="transmit" value="关闭并返回"/>
				
				
			</div>
		</div>
	</form>
</article>

<script type="text/javascript" src="template/jquery.min.js"></script> 
<script type="text/javascript" src="template/layer.js"></script>
<script type="text/javascript" src="template/laypage.js"></script> 
<script type="text/javascript" src="template/jquery.icheck.min.js"></script>
<script type="text/javascript" src="template/WdatePicker.js"></script> 
<script type="text/javascript" src="template/jquery.dataTables.min.js"></script> 
<script type="text/javascript" src="template/jquery.validate.min.js"></script> 
<script type="text/javascript" src="template/validate-methods.js"></script> 
<script type="text/javascript" src="template/messages_zh.min.js"></script>
<script type="text/javascript" src="template/H-ui.js"></script>
<a href="javascript:void(0)" class="Hui-iconfont toTop" title="返回顶部" alt="返回顶部" style="display:none"></a> 
<script type="text/javascript" src="template/H-ui.admin.js"></script> 
<script src="template/jquery.js" type="text/javascript"></script>
<script src="template/jquery.validate.js" type="text/javascript"></script>
<!--/_footer /ä½ä¸ºå¬å±æ¨¡çåç¦»åºå»--> 

 
<script type="text/javascript">
$(function(){

        //文本框失去焦点后 
       $('form :input').blur(function(){ 
            var $parent = $(this).parent(); 
            $parent.find(".formtips").remove(); 
            
            //验证合同数字编号 
            if( $(this).is('#numerical') ){ 
             
                     if(this.value==""){ 
                         var errorMsg = '不能为空.'; 
                         $parent.append('<span class="formtips onError" style="color:red">'+errorMsg+'</span>'); 
                     }
            	
                     else if( this.value=="" || this.value.length != 6||isNaN(this.value) == true ){ 
                       var errorMsg = '请输入6位的合同数字编号.'; 
                      
                       $parent.append('<span class="formtips onError"  style="color:red">'+errorMsg+'</span>'); 
                   }else if(this.value.trim()=="" || this.value.replace(/(^s*)|(s*$)/g, "").length ==0
									){
											var errorMsg = '输入内容不能为空格';

										$parent.append('<span class="formtips onError" style="color:red">'
														+ errorMsg + '</span>');
											
									} 
              
                	   
                	 //验证合同编号是否存在
                      else{ 
                                  //$parent.append('<span class="formtips onSuccess" style="color:green"></span>'); 
                              		check(this.value);
                              		//alert(return check(this.value));
                              		function check(contractnum){
              $.ajax({
                       //提交数据的类型 POST GET
                       type:"POST",
                       //提交的网址
                       url:"contractdetailnumcheck",
                       //提交的数据
                       data:{contractnum:contractnum},
                       //返回数据的格式
                       datatype: "text",//"xml", "html", "script", "json", "jsonp", "text".
                       //在请求之前调用的函数
                       //beforeSend:function(){$("#msg").html("logining");},
                       //成功返回之后调用的函数             
                       success:function(data){
                       if(data=="存在此合同编号"){
                       	$parent.append('<span class="formtips onSuccess" style="color:green"></span>');
                       }else{
                      		$parent.append('<span class="formtips onError" style="color:red">'+data+'</span>');
                      		}            
                       }   ,
                       //调用执行后调用的函数
                       complete: function(XMLHttpRequest, textStatus){
                       },
                       //调用出错执行的函数
                       error: function(){
                           //请求出错处理
                       }         
                    });

             }
                              } 
                       } 
                  
           

            //验证回款日期 
            if( $(this).is('#returntime') ){ 
               if( this.value==""  ){ 
                     var errorMsg = '回款日期不能为空.'; 
                     $parent.append('<span class="formtips onError" style="color:red" >'+errorMsg+'</span>'); 
               }else if(this.value.trim()=="" || this.value.replace(/(^s*)|(s*$)/g, "").length ==0
									){
											var errorMsg = '输入内容不能为空格';

										$parent.append('<span class="formtips onError" style="color:red">'
														+ errorMsg + '</span>');
											
									} 
               else{ 
                    
                     $parent.append('<span class="formtips onSuccess"></span>'); 
               } 
            } 
            
            
            //验证回款金额 
             if( $(this).is('#returnmoney') ){
            	 if( this.value==""  ){ 
                     var errorMsg ='不能为空.'; 
                     $parent.append('<span class="formtips onError" style="color:red">'+errorMsg+'</span>');}
            	 else if(this.value=="" ||  isNaN(this.value) == true   ){ 
                       var errorMsg = '请输入数字.'; 
                       $parent.append('<span class="formtips onError"  style="color:red">'+errorMsg+'</span>'); 
                   }else if(this.value.trim()=="" || this.value.replace(/(^s*)|(s*$)/g, "").length ==0
									){
											var errorMsg = '输入内容不能为空格';

										$parent.append('<span class="formtips onError" style="color:red">'
														+ errorMsg + '</span>');
											
									} 
                   else { 
               var numerical = $('#numerical').val();
               var returnmoney = $('#returnmoney').val();
              $.ajax({
                       //提交数据的类型 POST GET
                       type:"POST",
                       //提交的网址
                       url:"payment_max.jsp",
                       //提交的数据
                       data:{numerical:numerical,returnmoney:returnmoney},
                       //返回数据的格式
                       datatype: "text",//"xml", "html", "script", "json", "jsonp", "text".
                       //在请求之前调用的函数
                       //beforeSend:function(){$("#msg").html("logining");},
                       //成功返回之后调用的函数             
                       success:function(data){
                       if(data.replace(/\s/g,'')=="回款总金额不大于合同总额"){
                       	$parent.append('<span class="formtips onSuccess" style="color:green"></span>');
                       }else{
                      		$parent.append('<span class="formtips onError" style="color:red">'+data+'</span>');
                      		}            
                       }   ,
                       //调用执行后调用的函数
                       complete: function(XMLHttpRequest, textStatus){
                       },
                       //调用出错执行的函数
                       error: function(){
                           //请求出错处理
                       }         
                    });

             }
                              } 
       });
       /*.keyup(function(){ 
          $(this).triggerHandler("blur"); 
       }).focus(function(){ 
            $(this).triggerHandler("blur"); 
       });//end blur */
 
        
       $('#send').click(function() {
 		  $("form :input.required").trigger('blur');
 		  var numError=$('form .onError').length;
 		  if(numError!=0){
 		  	  return false;
 		  }
 		  else{
 		  	return true;
 		  }
 		
 		  
      }); 
     
})

	
</script> 
 <script type="text/javascript">
    $('#transmit').on('click', function(){
        //刷新页面
        parent.window.location.href='payment_detail.jsp?numerical=<%=bean.getNumerical()%>';
        //获取窗口索引
        var index = parent.layer.getFrameIndex(window.name);
        //关闭弹出层
        parent.layer.close(index);
    });
</script>

